package com.csust.reggie.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.csust.reggie.common.R;
import com.csust.reggie.domain.Orders;
import com.csust.reggie.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 订单
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private IOrderService orderService;

    /**
     * 用户下单
     * @param orders
     * @return
     */
    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders){
        log.info("订单数据：{}",orders);
        orderService.submit(orders);
        return R.success("下单成功");
    }

    @GetMapping("/page")
    public R<Page<Orders>>  page(Integer page, Integer pageSize, Long number, Date beginTime,Date endTime) {
        log.info("page = {} , pageSize = {}, startTime = {},endTime = {} ",page,pageSize,beginTime,endTime);
        Page<Orders> list = new Page<>();
        LambdaQueryWrapper<Orders> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(null != number,Orders::getNumber,number);
        queryWrapper.between(Orders::getOrderTime,beginTime,endTime);
        orderService.page(list,queryWrapper);
        return R.success(list);
    }
}
